<?php
	require_once("../process/session.php");
	$my_session = new session();
	$db = $my_session->getDB_torneig();

		print_r($_POST);
	if(dadesOk()){


		switch($_POST["function"]){
				
				
			/*********************	ELIMINAR EQUIP  *********************/	
			case "eliminar_equip";
		
					$delete = "Delete 
							   From	equips
							   Where nom = '".$_POST['eliminar_equip']."'" ;	
									
					if(!$db->executar($delete))
						echo "ERROR DELETE";
					else
						echo "CORRECTE";
					
				//}
				break;
				
			/*********************	CANVIAR CATEGORIA  *********************/	
			case "canviar_cat";
			
				if($_POST['desti'] != $_POST['origen']){
					$update = "Update equips Set categoria = '". $_POST['desti'] ."' Where categoria = '". $_POST['origen'] ."'"; 
					if(!$db->executar($update))
						echo "ERROR DELETE";
					else
						echo "CORRECTE";
				}
			break;

			/*********************	HORES  *********************/	
			case "marcats";
			
				$update = "Update equips Set pagament = 'n'";
				$db->executar($update);
				foreach ($_POST as $key => $value) {

					if($key != "function"){
						$update = "Update equips Set pagament = 's' Where nom = '". $value ."'";
						$db->executar($update);
					}
				}
				break;

			default:
		}


	}

	header("location: ../forms/f_admin_equips.php");
	
	function dadesOk(){
		if(!isset($_POST["function"]))	return false;
		
		switch($_POST["function"]){
			case "eliminar_equip":
				if(!isset($_POST["eliminar_equip"]) || $_POST['eliminar_equip'] == "")	return false;
				break;
			case "canviar_cat";
				if(!isset($_POST["origen"]) || $_POST["origen"] == "" || !isset($_POST["desti"]) || $_POST["desti"] == "")	return false;
				break;
			case "marcats";
				break;
			default:
		}
		return true;
		
	}
	
	
	
	
	
	
	
	
?>